package com.space.school.dao.impl;

import com.space.school.dao.LoginDao;
import com.space.school.domain.User;
import com.space.school.utils.SpaceJDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class LoginDaoImpl implements LoginDao {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(SpaceJDBCUtils.getDs());
    @Override
    public boolean login(String username, String password) {
        String sql = "select * from user where userName=? and passWord=?";
//        sql行的映射器  将sql 查询后的结果映射到集合中
        List<User> list=jdbcTemplate.query(sql,new BeanPropertyRowMapper<User>(User.class),username,password);
        if(list.size()>0){
            return true;
        }
        return false;
    }
    @Override
    public boolean usernameIsEmpty(String username) {
        String sql = "select * from user where userName=?";
//        sql行的映射器  将sql 查询后的结果映射到集合中
        List<User> list=jdbcTemplate.query(sql,new BeanPropertyRowMapper<User>(User.class),username);
        if(list.size()>0){
            return true;
        }
        return false;
    }
}
